<?php

$host = "localhost";
$user = "achatell";
$bdd = "achatell";
$passwd  = "**123456";

if(!function_exists('json_encode'))
{
	include_once('JSON.php');
	$GLOBALS['JSON_OBJECT'] = new Services_JSON();
	function json_encode($value)
	{
		return $GLOBALS['JSON_OBJECT']->encode($value); 
	}
	
	function json_decode($value)
	{
		return $GLOBALS['JSON_OBJECT']->decode($value); 
	}
}

function getLogin(){
	return mysql_real_escape_string($_REQUEST['login']);
}

function getToken(){
	if($_REQUEST['token']){
		return mysql_real_escape_string($_REQUEST['token']);
	} else {
		return sha1($_REQUEST['login'].$_REQUEST['password']);
	}
}

function getPassword(){
	return sha1($_REQUEST['password']);
}

function getExtension(){
	return mysql_real_escape_string($_REQUEST['extensionId']);
}

function getData(){
	return $_REQUEST['data'];
}

function getMessage(){
	return mysql_real_escape_string($_REQUEST['message']);
}



function isTokenExist(){
	$token_query = "SELECT token from ExtensionUser where token='" . getToken() . "';";
	$token_result = mysql_query($token_query);
	return mysql_num_rows($token_result) > 0;
}
?>